package com.meatball.id.base

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
import jakarta.persistence.MappedSuperclass
import org.hibernate.annotations.Comment
import org.hibernate.annotations.GenericGenerator
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.Instant
import java.time.LocalDateTime

/**
 * TODO 基础类
 *
 * @author 张翔宇
 * @since 2024年3月25日
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseEntity {
    @Id
    @GeneratedValue(generator = "snowflakeId")
    @GenericGenerator(name = "snowflakeId", strategy = "com.meatball.id.SnowflakeIdGenerator")
    @Column(nullable = true)
    @Comment("主键")
    var id: Long = 0L

    @CreatedDate
    @Column(nullable = false, updatable = false)
    @Comment("创建时间")
    var createdAt: LocalDateTime = LocalDateTime.now()

    @LastModifiedDate
    @Column(nullable = false)
    @Comment("更新时间")
    var updatedAt: LocalDateTime = LocalDateTime.now()
}